﻿// 麻省理工学院许可证
//
// 版权所有 (c) 2023-2025 缄默 联系电话/18521355630 
//
// 特此免费授予获得本软件的任何人以处理本软件的权利，但须遵守以下条件：在所有副本或重要部分的软件中必须包括上述版权声明和本许可声明。
//
// 软件按“原样”提供，不提供任何形式的明示或暗示的保证，包括但不限于对适销性、适用性和非侵权的保证。
// 在任何情况下，作者或版权持有人均不对任何索赔、损害或其他责任负责，无论是因合同、侵权或其他方式引起的，与软件或其使用或其他交易有关。

using Infragistics.Win.Misc;
using Infragistics.Win.UltraMessageBox;

namespace LvcChong
{
    public static class MessageHelper
    {
        private static UltraMessageBoxManager _ultraMessageBoxManager = new UltraMessageBoxManager() { ButtonAlignment = Infragistics.Win.HAlign.Right };

        public static DialogResult ShowInfomationBox(string message, string title = "提示", MessageBoxButtons messageBoxButtons = MessageBoxButtons.OK)
        {
            var info = new UltraMessageBoxInfo
            {
                Buttons = messageBoxButtons,
                Icon = MessageBoxIcon.Information,
                DefaultButton = MessageBoxDefaultButton.Button1,
                Caption = "提示",
                HeaderFormatted = $"<font color='#0066cc'>{title}</font>",
                TextFormatted = message,
                ShowHelpButton = Infragistics.Win.DefaultableBoolean.False,
                MinimumWidth = 400,
                FooterFormatted = "<b>技术支持：</b>华明集团-信息化办公室（付金龙: 18521355630）",
            };
            info.HeaderAppearance.ForeColor = Color.FromArgb(0, 153, 255);
            NLogHelper.Info(message);
            return _ultraMessageBoxManager.ShowMessageBox(info);
        }

        public static DialogResult ShowWarningBox(string message, string title = "警告", MessageBoxButtons messageBoxButtons = MessageBoxButtons.OK)
        {
            var info = new UltraMessageBoxInfo
            {
                Buttons = messageBoxButtons,
                Icon = MessageBoxIcon.Warning,
                DefaultButton = MessageBoxDefaultButton.Button1,
                Caption = "警告",
                HeaderFormatted = $"<font color='#0066cc'>{title}</font>",
                TextFormatted = message,
                ShowHelpButton = Infragistics.Win.DefaultableBoolean.False,
                MinimumWidth = 400,
                FooterFormatted = "<b>技术支持：</b>华明集团-信息化办公室（付金龙: 18521355630）",
            };
            info.HeaderAppearance.ForeColor = Color.FromArgb(0, 153, 255);
            NLogHelper.Info(message);
            return _ultraMessageBoxManager.ShowMessageBox(info);
        }

        public static DialogResult ShowErrorBox(string message, string title = "错误", MessageBoxButtons messageBoxButtons = MessageBoxButtons.OK)
        {
            var info = new UltraMessageBoxInfo
            {
                Buttons = messageBoxButtons,
                Icon = MessageBoxIcon.Error,
                DefaultButton = MessageBoxDefaultButton.Button1,
                Caption = "错误",
                HeaderFormatted = $"<font color='#0066cc'>{title}</font>",
                TextFormatted = message,
                ShowHelpButton = Infragistics.Win.DefaultableBoolean.False,
                MinimumWidth = 400,
                FooterFormatted = "<b>技术支持：</b>华明集团-信息化办公室（付金龙: 18521355630）",
            };
            info.HeaderAppearance.ForeColor = Color.FromArgb(0, 153, 255);
            NLogHelper.Info(message);
            return _ultraMessageBoxManager.ShowMessageBox(info);
        }

        public static DialogResult ShowQuestionBox(string message, string title = "提示", MessageBoxButtons messageBoxButtons = MessageBoxButtons.OKCancel)
        {
            var info = new UltraMessageBoxInfo
            {
                Buttons = messageBoxButtons,
                Icon = MessageBoxIcon.Question,
                DefaultButton = MessageBoxDefaultButton.Button1,
                Caption = "疑问",
                HeaderFormatted = $"<font color='#0066cc'>{title}</font>",
                TextFormatted = message,
                ShowHelpButton = Infragistics.Win.DefaultableBoolean.False,
                MinimumWidth = 400,
                FooterFormatted = "<b>技术支持：</b>华明集团-信息化办公室（付金龙: 18521355630）",
            };
            info.HeaderAppearance.ForeColor = Color.FromArgb(0, 153, 255);
            NLogHelper.Info(message);
            return _ultraMessageBoxManager.ShowMessageBox(info);
        }

        private static UltraDesktopAlert GenerateAlertInstance(Infragistics.Win.DefaultableBoolean autoClose = Infragistics.Win.DefaultableBoolean.True)
        {
            var _ultraDesktopAlert = new UltraDesktopAlert();
            _ultraDesktopAlert.Opacity = 1;
            _ultraDesktopAlert.AnimationSpeed = AnimationSpeed.Fast;
            _ultraDesktopAlert.AutoCloseDelay = 5000;
            _ultraDesktopAlert.AutoClose = autoClose;
            _ultraDesktopAlert.FixedSize = new Size(350, 150);
            _ultraDesktopAlert.AnimationScrollDirectionShow = AnimationScrollDirection.TopToBottom;
            _ultraDesktopAlert.AnimationScrollDirectionAutoClose = AnimationScrollDirection.LeftToRight;
            _ultraDesktopAlert.TextAppearance.TextHAlign = Infragistics.Win.HAlign.Left;
            _ultraDesktopAlert.TextAppearance.TextVAlign = Infragistics.Win.VAlign.Middle;
            return _ultraDesktopAlert;
        }

        public static void ShowDeskAlert(string message, object data = null, string title = "提示", Infragistics.Win.DefaultableBoolean autoClose = Infragistics.Win.DefaultableBoolean.True
            , DesktopAlertLinkClickedHandler desktopAlertLinkClicked = null)
        {
            var alert = GenerateAlertInstance(autoClose);
            if (desktopAlertLinkClicked != null) alert.DesktopAlertLinkClicked += desktopAlertLinkClicked;
            NLogHelper.Info(message);
            alert.Show(new UltraDesktopAlertShowWindowInfo(title, message) { Data = data });
        }

        public static void ShowDeskAlert(string message, Point point, object data = null, string title = "提示", Infragistics.Win.DefaultableBoolean autoClose = Infragistics.Win.DefaultableBoolean.True
            , DesktopAlertLinkClickedHandler desktopAlertLinkClicked = null)
        {
            var alert = GenerateAlertInstance(autoClose);
            if (desktopAlertLinkClicked != null) alert.DesktopAlertLinkClicked += desktopAlertLinkClicked;
            NLogHelper.Trace(message);
            alert.Show(new UltraDesktopAlertShowWindowInfo(title, message)
            {
                ScreenLocation = point,
                Data = data
            });
        }

        public static void ShowDeskAlert(string message, ScreenPosition screenPosition, string title = "提示", object data = null, Infragistics.Win.DefaultableBoolean autoClose = Infragistics.Win.DefaultableBoolean.True
            , DesktopAlertLinkClickedHandler desktopAlertLinkClicked = null)
        {
            var alert = GenerateAlertInstance(autoClose);
            if (desktopAlertLinkClicked != null) alert.DesktopAlertLinkClicked += desktopAlertLinkClicked;
            NLogHelper.Info(message);
            alert.Show(new UltraDesktopAlertShowWindowInfo(title, message)
            {
                ScreenPosition = screenPosition,
                Data = data
            });
        }
    }
}